package com.activenetwork.util.grid.condition;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class HasContentCondition implements Condition {

    private int column;
    private boolean hasContent;

    public int getColumn() {
		return column;
	}
	public void setColumn(int column) {
		this.column = column;
	}
	public boolean isHasContent() {
		return hasContent;
	}
	public void setHasContent(boolean hasContent) {
		this.hasContent = hasContent;
	}
	/**
	 * Empty constructor
	 */
	public HasContentCondition(){
		this.column = -1;
		this.hasContent = false;
	}
	/**
	 * Direct constructor
	 * @param column
	 * @param hasContent
	 */
	public HasContentCondition(int column, boolean hasContent) {
        this.column = column;
        this.hasContent = hasContent;
    }
	
	@Override
    public boolean matchs(WebElement row) {
        List<WebElement> webElements = row.findElements(By.xpath("./td["
                + column + "]/*"));
        boolean flag = webElements.size() > 0;
        return !flag ^ hasContent;
    }
}
